package cn.iocoder.yudao.module.promotion.job.coupon;

import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
import cn.iocoder.yudao.module.promotion.service.coupon.CouponService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 优惠券过期 Job
 *
 * @author owen
 */
@Component
@Slf4j
public class CouponExpireJob implements JobHandler {

    @Resource
    private CouponService couponService;

    @Override
    @TenantJob
    public String execute(String param) {
        log.info("[任务启动] 定时任务：优惠券过期处理开始执行");
        long startTime = System.currentTimeMillis();
        int count = couponService.expireCoupon();
        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        log.info("[任务完成] 优惠券过期处理完成：过期优惠券 {} 个，用时 {}ms", count, duration);
        return StrUtil.format("过期优惠券 {} 个", count);
    }

}
